import request from './request'

export const getCustomerList = (params) => {
  return request({
    url: '/customer',
    method: 'get',
    params
  })
}

export const createCustomer = (data) => {
  return request({
    url: '/customer/add',
    method: 'post',
    data
  })
}

export const updateCustomer = (data) => {
  return request({
    url: `/customer/${data.id}`,
    method: 'put',
    data
  })
}

export const deleteCustomer = (id) => {
  return request({
    url: `/customer/${id}`,
    method: 'delete'
  })
}

export const getCustomerDetail = (id) => {
  return request({
    url: `/customer/${id}`,
    method: 'get'
  })
}

export const exportCustomer = () => {
  return request({
    url: '/customer/export',
    method: 'get',
    responseType: 'blob'
  })
}

export const importCustomer = (file) => {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/customer/import',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export const searchCustomers = (params) => {
  return request({
    url: '/customer/search',
    method: 'get',
    params
  })
}